package com.fit.pages.sold_product;

import java.util.List;

import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.fit.annotations.AdminAccess;
import com.fit.annotations.UserAccess;
import com.fit.dao.product.ProductDAO;
import com.fit.dao.sold_product.SoldDAO;
import com.fit.dao.user.UserDAO;
import com.fit.entities.Product;
import com.fit.entities.Sold_product;
import com.fit.entities.User;

@AdminAccess
@UserAccess
public class Details {

	@Property
	@Persist
	private Sold_product sold_product;
	
	@Property
	@Persist
	private Product product;
	
	@Inject
	private ProductDAO productDAO;
	
	@Inject
	private SoldDAO soldDAO;
	
	public boolean isUserNotNull(){
		if(sold_product.getUser()!=null){
			return true;
		} else {
			return false;
		}
	}
	
	public boolean isProductNotNull(){
		if(sold_product.getProduct()!=null){
			return true;
		} else {
			return false;
		}
	}
	
	Object onActivate(Long id) {
		sold_product = soldDAO.findById(id);
		
		return null;

	}
	
	public double cijena(){
		double d;
		
//		product = productDAO.findById(sold_product.getProduct().id);
		d = sold_product.getItems_sold() * sold_product.getProduct().getPrice();
		
		return d;
	}
	
	

}
